# -*- coding: utf-8 -*-
"""
Created on Sun Sep  5 16:26:59 2021

@author: vrs
"""

import math
import numpy as np
from PIL import Image, ImageFont, ImageDraw

import matplotlib.pylab as plt
import matplotlib.image as mpimg


def rgb2gray(rgb): 
     r, g, b = rgb[:,:, 0 ], rgb[:,:, 1 ], rgb[:,:, 2 ]
     gray = 0.2989 * r + 0.5870 * g + 0.1140 * b 
     return gray




#im = Image.open("lena.jpg") # read the image, provide the correct path

im_original = mpimg.imread("lena.jpg")
im_car = mpimg.imread("car.jpg")

print(im_original.shape, im_original.dtype, type(im_original)) # this image contains anα
plt.imshow(im_original) # display the image

plt.imshow(im_car) # display the image
#plt.axis('off')


"转换成灰度图像"
img_grey= rgb2gray(im_original)
plt.imshow(img_grey,cmap = plt.get_cmap( 'gray'))
print(img_grey.shape, img_grey.dtype, type(img_grey))


"两个图像各乘一个值后叠加"
im_new_01=np.round(im_original*0.5+im_car*0.5,decimals=0)

'转换为int型'
im_new_01=im_new_01.astype(np.int)   
plt.imshow(im_new_01)



"图像用255-原始值"
#im255=np.zeros(shape=im.shape)
im255=np.ones(shape=im_original.shape)*255
im_new_02=im255-im_original
im_new_02=im_new_02.astype(np.int) 

 
plt.imshow(im_new_02) # display the image